package com.gxc.service.user.controller;

import com.gxc.service.common.model.ServerResponse;
import com.gxc.service.user.feign.GoodsFeign;
import com.gxc.service.user.model.dto.GetFeignTestDto;
import com.gxc.service.user.model.dto.ProductDto;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @author GongXincheng
 * @since 2019-11-08 22:15
 */
@RestController
@RequestMapping("/feign/product")
public class ProductFeignController {

    @Resource
    private GoodsFeign goodsFeign;

    /**
     * 批量新增
     */
    @GetMapping("/add")
    public ServerResponse<List<ProductDto>> add() {
        return goodsFeign.add();
    }

    /**
     * 根据id查询.
     */
    @GetMapping("/{id}")
    public ServerResponse<ProductDto> findById(@PathVariable Long id) {
        return goodsFeign.findById(id);
    }

    /**
     * 模糊查询
     */
    @GetMapping("/search")
    public ServerResponse<List<ProductDto>> likeSearch(@RequestParam String name) {
        return goodsFeign.likeSearch(name);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public ServerResponse<ProductDto> save(@RequestBody ProductDto entity) {
        return goodsFeign.save(entity);
    }


    @GetMapping("/test-get")
    public ServerResponse<GetFeignTestDto> testGetFeign() {
        GetFeignTestDto dto = new GetFeignTestDto();
        dto.setId(1);
        dto.setDate(new Date());
        dto.setLocalDateTime(LocalDateTime.now());
        dto.setName("admin_gxc");
        return goodsFeign.feignGetTest(dto);
    }
}
